package com.fengxing.ams.web.action.view;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class GraphLabelNamePair {

	private String label;
	private Integer value;
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public Integer getValue() {
		return value;
	}
	public void setValue(Integer value) {
		this.value = value;
	}
	
	public GraphLabelNamePair(String label) {
		this.label = label;
	}
	
	public GraphLabelNamePair(String label, Integer value) {
		this.label = label;
		this.value = value;
	}
	
	public GraphLabelNamePair() {
		
	}
	
	public static List<GraphLabelNamePair> builderPairList(Map<String, Integer> maps) {
		List<GraphLabelNamePair> list = new ArrayList<GraphLabelNamePair> (maps.size());
		Iterator<Entry<String, Integer>> iter = maps.entrySet().iterator();
		while (iter.hasNext()) {
			Entry<String, Integer> me = iter.next();
			list.add(new GraphLabelNamePair(me.getKey(), me.getValue()));
		}
		Collections.sort(list, new Comparator<GraphLabelNamePair> (){
			public int compare(GraphLabelNamePair o1, GraphLabelNamePair o2) {
				return o2.value - o1.value;
			}
		});
		return list;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((label == null) ? 0 : label.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GraphLabelNamePair other = (GraphLabelNamePair) obj;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}
	
}
